﻿using System;
using System.Collections.Generic;
using System.IO;

namespace FRAFV.Binary.Serialization
{
	class Program
	{
		static void Main(string[] args)
		{
			using (var file = new StreamReader(args[0], true))
			{
				var code = file.ReadToEnd();

				var gen = new ClassGenerator(code);
				var errors = new List<string>();
				var code2 = gen.GenerateSerializer(
					(message, row, column) =>
					{
						Console.ForegroundColor = ConsoleColor.Yellow;
						if (row != unchecked((uint)-1))
							message = String.Format("({0},{1}) {2}", row + 1, column + 1, message);
						Console.Error.WriteLine(message);
						Console.ResetColor();
						errors.Add(message);
					});
				if (code2 != null)
					Console.WriteLine(code2);
				Console.ForegroundColor = ConsoleColor.Red;
				foreach (string error in errors)
					Console.Error.WriteLine(error);

				//var childer = ClassParser.GetPartials(code);
				//foreach (var child in childer)
				//{
				//	Console.WriteLine("[{2}] partial class {0}.{1}", child.Namespace, child.Name, child.BinBlock.ToString());
				//	foreach (var prop in child.Properties)
				//	{
				//		Console.WriteLine("[{3}] {2} {0}.{1}", child.Name, prop.Name, prop.Type, prop.BinData.ToString());
				//	}
				//}

				Console.ResetColor();
				Console.ReadKey();
			}
		}
	}
}
